package com.shenhaofeng.app.adapter;

import android.support.v7.widget.RecyclerView;


/**
 *适配器空数据的观察者
 * Created by Administrator on 2016/5/23.
 */
public class EmptyAdapterDataObservable extends RecyclerView.AdapterDataObserver {

    protected Callback callback;
    protected RecyclerView.Adapter adapter;


    public EmptyAdapterDataObservable(Callback callback, RecyclerView.Adapter adapter) {
        this.callback = callback;
        this.adapter = adapter;
    }


    @Override
    public void onChanged() {
        checkEmpty();
    }


    @Override
    public void onItemRangeInserted(int positionStart, int itemCount) {
        checkEmpty();
    }


    @Override
    public void onItemRangeRemoved(int positionStart, int itemCount) {
        checkEmpty();
    }


    protected void checkEmpty() {
        callback.onEmpty(adapter.getItemCount() == 0);
    }


    public interface Callback {

        /**
         * 在数据为空时将会被调用
         * @param empty
         */
        void onEmpty(boolean empty);
    }


}
